<template>
	<view class="pay-result">
		<!-- #ifdef MP || APP-PLUS -->
		<u-navbar title="交易结果" :is-back="false" titleColor="#141414"></u-navbar>
		<!-- #endif -->
		<view class="result-box" v-if="type==='success'">
			<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/result/icon1.png"></image>
			<view class="result-tit">交易成功</view>
			<view class="result-price">￥<text>{{money}}</text></view>
		</view>
		<view class="result-box" v-if="type==='fail'">
			<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/result/icon2.png"></image>
			<view class="result-tit">交易失败</view>
			<view class="result-price">￥<text>{{money}}</text></view>
		</view>
		<view class="pay-result-btns">
			<view class="back-home" @click="backHome">返回首页</view>
			<view class="check-order" @click="goOrder">查看订单</view>
		</view>
		<view class="pay-recomment" v-if="show">
			<view class="pay-recomment-tit">
				<view class="pay-recomment-tit-main">为您推荐</view>
				<view class="pay-recomment-tit-sub">Recommended for you</view>
			</view>
			<view class="pay-recomment-pro">
				<pt-product-items
					:showSort="false"
					:object="{goods_list: list}"
					:noMore="true"
					@goProInfo="goProInfo"
					:isLogin="isLogin">
				</pt-product-items>
				<pt-loading v-if="isLoading"></pt-loading>
				<pt-nomore v-if="noMore && list.length"></pt-nomore>
				<pt-nothing
					v-if="noMore && !list.length"
					text="暂无商品"
					icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1"
					:isHigh="true"></pt-nothing>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '',
				money: '',
				list: [],
				show: false,
				page: 0,
				isLoading: false,
				noMore: false,
				isLogin: false
			};
		},
		onShow() {
			if(uni.getStorageSync('userInfo')){
				this.isLogin = true
			}else{
				this.isLogin = false
			}
		},
		onLoad(options) {
			this.type = options.type
			this.money = options.price
			this.getRecommentList()
		},
		methods: {
			backHome(){
				// #ifdef MP-WEIXIN
				if(uni.getExtConfigSync().appid==='wx9f2da8a90bb750f7'){
					uni.switchTab({
						url: '/pages/merchant/merchant'
					})
				}else{
					uni.switchTab({
						url: '/pages/index/index'
					})
				}
				// #endif
				// #ifdef APP-PLUS || H5
				uni.switchTab({
					url: '/pages/index/index'
				})
				// #endif
			},
			goOrder(){
				uni.redirectTo({
					url: '/my/my-order/my-order?current=0'
				})
			},
			goProInfo(goods_id){
				getApp().goProInfo(goods_id)
			},
			getRecommentList(){
				this.$u.api.SearchRecommendList({page: this.page}).then(res => {
					this.isLoading = false
					this.show = true
					if(res.datas.data.length){
						res.datas.data.forEach(item => {
							this.list.push(item)
						})
					}else{
						this.noMore = true
					}
				})
			}
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.isLoading = true
				this.getRecommentList()
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F9F9F9;
	}
	.pay-result{
		.result-box{
			text-align: center;
			background-color: #FFF;
			padding: 80rpx 50rpx 50rpx;
			image{
				width: 96rpx;
				height: 96rpx;
			}
			.result-tit{
				margin-top: 50rpx;
				font-size: 36rpx;
				color: #141414;
				font-weight: bold;
			}
			.result-price{
				margin-top: 30rpx;
				font-weight: bold;
				font-size: 24rpx;
				color: #141414;
				text{
					font-size: 36rpx;
				}
			}
		}
		.pay-result-btns{
			padding: 20rpx 115rpx 80rpx;
			background-color: #FFF;
			display: flex;
			align-items: center;
			justify-content: space-between;
			view{
				width: 240rpx;
				height: 80rpx;
				border: solid 2rpx #444;
				border-radius: 8rpx;
				line-height: 76rpx;
				text-align: center;
				font-size: 28rpx;
				color: #444;
				&.check-order{
					background-color: #141414;
					border-color: #141414;
					color: #FFF;
				}
			}
		}
		.pay-recomment{
			background-color: #FFF;
			margin-top: 30rpx;
			.pay-recomment-tit{
				text-align: center;
				padding: 50rpx 0;
				.pay-recomment-tit-main{
					font-size: 42rpx;
					color: #141414;
					font-weight: bold;
				}
				.pay-recomment-tit-sub{
					margin-top: 20rpx;
					text-transform: uppercase;
					font-family: 'Microsoft YaHei Light';
					color: #666;
				}
			}
			.pay-recomment-pro{
				padding: 0 30rpx;
			}
		}
	}
</style>
